/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {Form, Input, Alert, Select, Switch, InputNumber} from 'antd';
import {connect} from 'dva';
const FormItem = Form.Item;
const Option = Select.Option;
@connect(({roles}) => ({
  roles
}))
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      showCustom: false
    };
  }

  componentDidMount() {
    const {dispatch} = this.props;
  }

  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
                层级
            </span>
            )}
          >
            {getFieldDecorator('level', {
              initialValue:{label:'层级一',key:'1'},
              rules: [{required: true}],
            })(
              <Select  labelInValue={true}>
                { [{name:'层级一',id:'1'},{name:'层级二',id:'2'}].map((item, key) => {
                  return (
                    <Option key={item.id}
                            value={item.id}>{item.name}</Option>
                  )
                }) }
              </Select>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               初始佣金(元)
            </span>
            )}
          >
            {getFieldDecorator('initial_commission', {
              initialValue: 0,
              rules: [{required: true,message: '初始佣金不能为空'}],
            })(
              <InputNumber min={0} style={{width:'100%'}}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               晋升后佣金(元)
            </span>
            )}
          >
            {getFieldDecorator('promotion_commission', {
              initialValue: 0,
              rules: [{required: true,message: '晋升后佣金不能为空'}],
            })(
              <InputNumber min={0} style={{width:'100%'}}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               晋升条件(个)
            </span>
            )}
          >
            {getFieldDecorator('promotion_conditions', {
              initialValue: 0,
              rules: [{required: true,message: '晋升条件不能为空'}],
            })(
              <InputNumber min={0} style={{width:'100%'}}/>
            )}
          </FormItem>
          <div style={{width:'80%',margin:'0 auto'}}>
            <Alert message="当不能晋升时，晋升后佣金、晋升条件都设置为0" type="warning" />
          </div>

        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


